package org.jeecg.modules.api.xxApi.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.api.xxApi.service.IDjts;
import org.jeecg.modules.api.xxApi.vo.*;
import org.jeecg.modules.common.util.Convert;
import org.jeecg.modules.innerApi.common.requestDto.InvoiceParam;
import org.jeecg.modules.qyxx.entity.CsPtQyxx;
import org.jeecg.modules.qyxx.service.ICsPtQyxxService;
import org.jeecg.modules.xxgx.common.util.FPUtil;
import org.jeecg.modules.xxgx.djgl.entity.*;
import org.jeecg.modules.xxgx.djgl.entity.cezs.Cezs;
import org.jeecg.modules.xxgx.djgl.service.*;
import org.jeecg.modules.xxgx.fjys.entity.CsXxFjys;
import org.jeecg.modules.xxgx.fjys.service.ICsXxFjysService;
import org.jeecg.modules.xxgx.fjys.vo.FjysVO;
import org.jeecg.modules.xxgx.fpgl.entity.CsXxFpxx;
import org.jeecg.modules.xxgx.fpgl.service.ICsXxFpxxService;
import org.jeecg.modules.xxgx.khgl.entity.CsXxCustom;
import org.jeecg.modules.xxgx.khgl.service.ICsXxCustomService;
import org.jeecg.modules.xxgx.kpzdgl.entity.CsXxKpzd;
import org.jeecg.modules.xxgx.kpzdgl.service.ICsXxKpzdService;
import org.jeecg.modules.xxgx.spgl.entity.CsXxProduct;
import org.jeecg.modules.xxgx.spgl.service.ICsXxProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

@Transactional
@Service
public class DjtsImpl implements IDjts {

    @Autowired
    private ICsXxKpzdService iCsXxKpzdService;

    @Autowired
    private ICsXxDkdjService iCsXxDkdjService;

    @Autowired
    private ICsXxYkdjService iCsXxYkdjService;

    @Autowired
    private ICsXxFpxxService iCsXxFpxxService;

    @Autowired
    private ICsXxDkdjmxService iCsXxDkdjmxService;

    @Autowired
    private ICsPtQyxxService iCsPtQyxxService;

    @Autowired
    private ICsXxCustomService iCsXxCustomService;

    @Autowired
    private ICsXxProductService iCsXxProductService;

    @Autowired
    private ICsXxDkdjExtService iCsXxDkdjExtService;

    @Autowired
    private ICsXxDkdjCezsService iCsXxDkdjCezsService;

    @Autowired
    private ICsXxFjysService iCsXxFjysService;

    @Override
    public XxApiDjtsResult djts(XxApiDjtsParam xxApiDjtsParam, String callbackurl) {
        XxApiDjtsResult result = new XxApiDjtsResult();
        //首选查询 基础信息  根据开票终端代码
        String kpzddm = xxApiDjtsParam.getKpzddm();
        List<CsXxKpzd> kpzdlist = iCsXxKpzdService.lambdaQuery().eq(StringUtils.isNotEmpty(kpzddm), CsXxKpzd::getZddm, kpzddm).list();
        if (kpzdlist.isEmpty()) {
            throw new JeecgBootException("根据开票终端代码：" + kpzddm + ",未查询到开票终端，请核实！");
        }
        CsXxKpzd kpzd = kpzdlist.get(0);
        String tenant_id = Convert.toStr(kpzd.getTenantId());
        String company_id = kpzd.getCompanyId();
        String sys_org_code = StringUtils.isBlank(xxApiDjtsParam.getBmdm()) ? kpzd.getSysOrgCode() : xxApiDjtsParam.getBmdm();

        //判断ywdjbh是否重复
        List<CsXxDkdj> dkdjlist = iCsXxDkdjService.lambdaQuery().eq(CsXxDkdj::getYwdjbh, xxApiDjtsParam.getYwdjbh()).list();
        List<CsXxYkdj> ykdjlist = iCsXxYkdjService.lambdaQuery().eq(CsXxYkdj::getYwdjbh, xxApiDjtsParam.getYwdjbh()).list();
        if (!dkdjlist.isEmpty()) {
            throw new JeecgBootException("ywdjbh:" + xxApiDjtsParam.getYwdjbh() + "重复！");
        }
        if (!ykdjlist.isEmpty()) {
            List<CsXxFpxx> fpxxlist = iCsXxFpxxService.lambdaQuery().eq(CsXxFpxx::getDjbh, ykdjlist.get(0).getId()).list();
            if (!fpxxlist.isEmpty()) {
                String fplxdm = fpxxlist.get(0).getFplxdm();
                if ("01".equals(fplxdm) || "02".equals(fplxdm)) {
                    throw new JeecgBootException("ywdjbh" + xxApiDjtsParam.getYwdjbh() + "已开票。发票号码：" + fpxxlist.get(0).getFphm());
                } else {
                    throw new JeecgBootException("ywdjbh" + xxApiDjtsParam.getYwdjbh() + "已开票。发票号码：" + fpxxlist.get(0).getFphm() + ",发票代码：" + fpxxlist.get(0).getFpdm());
                }
            }
        }

        //内容校验
        this.checkDjData(xxApiDjtsParam);

        CsXxDkdj csXxDkdj = new CsXxDkdj();
        //如果传的有bmdm 则赋值bmdm 否则 赋值开票终端对应的sysorgcode
        xxApiDjtsParam.setSysOrgCode(sys_org_code);
        BeanUtils.copyProperties(xxApiDjtsParam, csXxDkdj);

        //填充基本信息
        this.fillBasicInfo(xxApiDjtsParam, csXxDkdj);
        //填充客户信息
        this.filKhInfo(xxApiDjtsParam, csXxDkdj);

        List<XxApiDjtsMxParam> items = xxApiDjtsParam.getItems();
        List<CsXxDkdjmx> csXxDkdjmxList = new ArrayList<>();
        for (XxApiDjtsMxParam xxApiDjtsMxParam : items) {
            CsXxDkdjmx csXxDkdjmx = new CsXxDkdjmx();
            BeanUtils.copyProperties(xxApiDjtsMxParam, csXxDkdjmx);
            csXxDkdjmxList.add(csXxDkdjmx);
        }

        //处理明细数据
        this.generateMx(csXxDkdjmxList, csXxDkdj);

        //开始保存
        iCsXxDkdjService.save(csXxDkdj);
        iCsXxDkdjmxService.saveBatch(csXxDkdjmxList);
        CsXxDkdjExt csXxDkdjExt = new CsXxDkdjExt();
        try {
            //处理特定业务
            if (StringUtils.isNotBlank(xxApiDjtsParam.getTdyslxdm())) {
                switch (xxApiDjtsParam.getTdyslxdm()) {
                    case "03":
                        csXxDkdjExt.setTdywInfo(JSONObject.toJSONString(xxApiDjtsParam.getJzfw()));
                        break;
                    case "04":
                        csXxDkdjExt.setTdywInfo(JSONObject.toJSONString(xxApiDjtsParam.getHwysfw()));
                        break;
                    case "05":
                        csXxDkdjExt.setTdywInfo(JSONObject.toJSONString(xxApiDjtsParam.getBdcxsfw()));
                        break;
                    case "06":
                        csXxDkdjExt.setTdywInfo(JSONObject.toJSONString(xxApiDjtsParam.getBdcjyzlfw()));
                        break;
                    case "09":
                        csXxDkdjExt.setTdywInfo(JSONObject.toJSONString(xxApiDjtsParam.getLkysfwmx()));
                        break;
                    default:
                }
            }
        } catch (Exception e) {
            throw new JeecgBootException(e.getMessage());
        }

        //处理附加要素
        List<XxApiDjtsjFjysMxParam> fjyslist = xxApiDjtsParam.getFjyslist();
        List<FjysVO> fjysVOList = new ArrayList<>();
        if (fjyslist != null && !fjyslist.isEmpty()) {
            for (XxApiDjtsjFjysMxParam xxApiDjtsjFjysMxParam : fjyslist) {
                FjysVO fjysVO = new FjysVO();
                String xmmc = xxApiDjtsjFjysMxParam.getXmmc();
                QueryWrapper<CsXxFjys> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("xmmc", xmmc);
                queryWrapper.eq("company_id", company_id);
                List<CsXxFjys> list = iCsXxFjysService.list(queryWrapper);
                if (!list.isEmpty()) {
                    CsXxFjys csXxFjys = list.get(0);
                    fjysVO.setSjlx(csXxFjys.getSjlx());
                    fjysVO.setFjysuuid(csXxFjys.getFjysuuid());
                    fjysVO.setXmmc(xmmc);
                    fjysVO.setFjysz(xxApiDjtsjFjysMxParam.getContent());
                    fjysVOList.add(fjysVO);
                }
            }
            if (!fjysVOList.isEmpty()) {
                csXxDkdjExt.setFjysInfo(JSONObject.toJSONString(fjysVOList));
            }
        }
        if (!"".equals(csXxDkdjExt.getTdywInfo()) || !"".equals(csXxDkdjExt.getFjysInfo())) {
            csXxDkdjExt.setId(IdWorker.getIdStr());
            csXxDkdjExt.setCompanyId(company_id);
            csXxDkdjExt.setTenantId(Integer.valueOf(tenant_id));
            csXxDkdjExt.setFromid(csXxDkdj.getId());
            iCsXxDkdjExtService.save(csXxDkdjExt);
        }

        //处理差额征收
        List<Cezs> cezsList = xxApiDjtsParam.getCezsList();
        if (cezsList != null && !cezsList.isEmpty()) {
            for (Cezs cezs : cezsList) {
                CsXxDkdjCezs csXxDkdjCezs = new CsXxDkdjCezs();
                cezs.setId(IdWorker.getIdStr());
                cezs.setFromid(csXxDkdj.getId());
                cezs.setTenantId(tenant_id);
                cezs.setSysOrgCode(sys_org_code);
                cezs.setCompanyId(company_id);
                BeanUtils.copyProperties(cezs, csXxDkdjCezs);
                iCsXxDkdjCezsService.save(csXxDkdjCezs);
            }
        }
        result.setZt("0");
        result.setYwdjbh(xxApiDjtsParam.getYwdjbh());
        result.setSjlx(xxApiDjtsParam.getSjlx());
        return result;
    }

    @Override
    public CsXxKpzd queryKpzdBykpzddm(String kpzddm) {
        List<CsXxKpzd> kpzdlist = iCsXxKpzdService.lambdaQuery().eq(StringUtils.isNotEmpty(kpzddm), CsXxKpzd::getZddm, kpzddm).list();
        if (kpzdlist.isEmpty()) {
            throw new JeecgBootException("根据开票终端代码：" + kpzddm + ",未查询到开票终端，请核实！");
        }
        return kpzdlist.get(0);
    }


    /**
     * 处理附加要素
     *
     * @param xxApiFpkjParam
     * @param invoiceParam
     */
    @Override
    public void handleFjys(XxApiFpkjParam xxApiFpkjParam, InvoiceParam invoiceParam) {
        List<XxApiFpkjFjysMxParam> fjyslist = xxApiFpkjParam.getFjyslist();
        CsXxKpzd csXxKpzd = queryKpzdBykpzddm(xxApiFpkjParam.getKpzddm());
        List<FjysVO> fjysVOList = new ArrayList<>();
        if (fjyslist != null && !fjyslist.isEmpty()) {
            for (XxApiFpkjFjysMxParam apiFpkjFjysMxParam : fjyslist) {
                FjysVO fjysVO = new FjysVO();
                String xmmc = apiFpkjFjysMxParam.getXmmc();
                QueryWrapper<CsXxFjys> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("xmmc", xmmc);
                queryWrapper.eq("company_id", csXxKpzd.getCompanyId());
                List<CsXxFjys> list = iCsXxFjysService.list(queryWrapper);
                if (!list.isEmpty()) {
                    CsXxFjys csXxFjys = list.get(0);
                    fjysVO.setXmmc(xmmc);
                    fjysVO.setFjysuuid(csXxFjys.getFjysuuid());
                    fjysVO.setFjysz(apiFpkjFjysMxParam.getContent());
                    fjysVOList.add(fjysVO);
                }
            }
            if (!fjysVOList.isEmpty()) {
                invoiceParam.setFjysList(fjysVOList);
            }
        }
    }

    public void generateMx(List<CsXxDkdjmx> csXxDkdjmxlist, CsXxDkdj csXxDkdj) {
        for (CsXxDkdjmx csXxDkdjmx : csXxDkdjmxlist) {
            csXxDkdjmx.setFromid(csXxDkdj.getId());
            csXxDkdjmx.setId(IdWorker.getIdStr());
            csXxDkdjmx.setYwdjbh(csXxDkdj.getYwdjbh());
            csXxDkdjmx.setTenantId(csXxDkdj.getTenantId());
            csXxDkdjmx.setCompanyId(csXxDkdj.getCompanyId());

            String spmc = csXxDkdjmx.getSpmc();
            LambdaQueryWrapper<CsXxProduct> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(CsXxProduct::getSpmc, spmc);
            queryWrapper.eq(StringUtils.isNotBlank(csXxDkdjmx.getSpdm()), CsXxProduct::getSpdm, csXxDkdjmx.getSpdm());
            queryWrapper.eq(CsXxProduct::getSysOrgCode, csXxDkdj.getSysOrgCode());
            queryWrapper.orderByDesc(CsXxProduct::getSpbm);
            CsXxProduct csXxProduct = iCsXxProductService.getOne(queryWrapper, false);
            csXxProduct = Optional.ofNullable(csXxProduct).orElse(new CsXxProduct());
            if (StringUtils.isBlank(csXxDkdjmx.getSpdm())) {
                csXxDkdjmx.setSpdm(csXxProduct.getSpdm());
            }
            if (StringUtils.isBlank(csXxDkdjmx.getGgxh())) {
                csXxDkdjmx.setGgxh(csXxProduct.getGgxh());
            }
            if (StringUtils.isBlank(csXxDkdjmx.getJldw())) {
                csXxDkdjmx.setJldw(csXxProduct.getJldw());
            }
            if (StringUtils.isBlank(csXxDkdjmx.getSpbm())) {
                csXxDkdjmx.setSpbm(csXxProduct.getSpbm());
            }
            if (StringUtils.isBlank(csXxDkdjmx.getLslbs())) {
                csXxDkdjmx.setLslbs(csXxProduct.getLslbs());
            }
            if (StringUtils.isBlank(csXxDkdjmx.getYhzcbs())) {
                csXxDkdjmx.setYhzcbs(csXxProduct.getYhzcbs());
            }
            if (StringUtils.isBlank(csXxDkdjmx.getZzstsgl())) {
                csXxDkdjmx.setZzstsgl(csXxProduct.getZzstsgl());
            }
            if (StringUtils.isBlank(csXxDkdjmx.getSsmc())) {
                csXxDkdjmx.setSsmc(csXxProduct.getSpssjc());
            }

            if (csXxDkdjmx.getZkje() != null && csXxDkdjmx.getZkje().compareTo(BigDecimal.ZERO) > 0) {
                csXxDkdjmx.setFphxz("2");
            } else {
                csXxDkdjmx.setFphxz("0");
            }

            //差额征税
            if (StringUtils.isNotEmpty(csXxDkdj.getZsfs()) && "2".equals(csXxDkdj.getZsfs())) {
                calcMxBycezs(csXxDkdj.getKce(), csXxDkdjmx);
            } else {
                //正常
                FPUtil.calcItem(csXxDkdjmx, csXxDkdj.getTspz());
            }
        }
    }

    public void calcMxBycezs(BigDecimal kce, CsXxDkdjmx mx) {
        BigDecimal tax = mx.getTaxje();
        BigDecimal hsje = mx.getHsje();
        //（价税合计-扣除额）*税率/（1+税率）
        BigDecimal se = hsje.subtract(kce).multiply(tax).divide(BigDecimal.ONE.add(tax), 2, BigDecimal.ROUND_HALF_UP);
        BigDecimal bhsje = mx.getBhsje() != null ? mx.getBhsje() : hsje.subtract(se);
        mx.setTaxje(se);
        mx.setHsje(hsje);
        mx.setBhsje(bhsje);
        if (mx.getHsdj() == null) {
            mx.setHsdj(hsje.divide(mx.getSpsl(), 10, BigDecimal.ROUND_HALF_UP).stripTrailingZeros());
        }
        if (mx.getBhsdj() == null) {
            mx.setBhsdj(bhsje.divide(mx.getSpsl(), 10, BigDecimal.ROUND_HALF_UP).stripTrailingZeros());
        }
    }


    public void checkDjData(XxApiDjtsParam xxApiDjtsParam) {
        if ("1".equals(xxApiDjtsParam.getKplx()) || "3".equals(xxApiDjtsParam.getKplx())) {
            if ("01".equals(xxApiDjtsParam.getFplxdm()) || "02".equals(xxApiDjtsParam.getFplxdm())) {
                //数电票
                if ("".equals(xxApiDjtsParam.getYfphm())) {
                    throw new JeecgBootException("数电票红冲单据，原发票号码不能为空！");
                }
            } else {
                //税控票
                if ("".equals(xxApiDjtsParam.getYfphm()) || "".equals(xxApiDjtsParam.getYfpdm())) {
                    throw new JeecgBootException("作废或红冲单据，原发票号码或原发票代码不能为空！");
                }
            }
        }

        if ("1".equals(xxApiDjtsParam.getKplx())) {
            if ("".equals(xxApiDjtsParam.getHcyy())) {
                throw new JeecgBootException("红冲单据，红冲原因不能为空！");
            }
        }

        //校验明细累加金额是否和单据金额一致
        List<XxApiDjtsMxParam> mxlist = xxApiDjtsParam.getItems();
        BigDecimal mxSumHsje = BigDecimal.ZERO;
        BigDecimal mxSumBhsje = BigDecimal.ZERO;
        BigDecimal mxSubtractZkSumHsje = BigDecimal.ZERO;
        BigDecimal mxSubtractZkSumBhsje = BigDecimal.ZERO;
        for (XxApiDjtsMxParam djtsMx : mxlist) {
            String hsje = Convert.toStr(djtsMx.getHsje(), "0");
            String bhsje = Convert.toStr(djtsMx.getBhsje(), "0");
            if (StringUtils.isNotBlank(hsje)) {
                mxSumHsje = mxSumHsje.add(new BigDecimal(hsje));
                mxSubtractZkSumHsje = mxSubtractZkSumHsje.add(new BigDecimal(hsje));
                if (StringUtils.isNotBlank(Convert.toStr(djtsMx.getZkje()))) {
                    mxSubtractZkSumHsje = mxSubtractZkSumHsje.subtract(djtsMx.getZkje());
                }
            }
            if (StringUtils.isNotBlank(bhsje)) {
                mxSumBhsje = mxSumBhsje.add(new BigDecimal(bhsje));
                mxSubtractZkSumBhsje = mxSubtractZkSumBhsje.add(new BigDecimal(bhsje));
                if (StringUtils.isNotBlank(Convert.toStr(djtsMx.getZkje()))) {
                    mxSubtractZkSumBhsje = mxSubtractZkSumBhsje.subtract(djtsMx.getZkje());
                }
            }
        }
        boolean sumjePass;
        if (StringUtils.equals(xxApiDjtsParam.getHsbz(), "0")) {
            if (xxApiDjtsParam.getJe().compareTo(mxSumBhsje) == 0 || xxApiDjtsParam.getJe().compareTo(mxSubtractZkSumBhsje) == 0) {
                sumjePass = true;
            } else {
                sumjePass = false;
            }
        } else {
            if (xxApiDjtsParam.getJe().compareTo(mxSumHsje) == 0 || xxApiDjtsParam.getJe().compareTo(mxSubtractZkSumHsje) == 0) {
                sumjePass = true;
            } else {
                sumjePass = false;
            }
        }
        if (!sumjePass) {
            throw new JeecgBootException("明细金额累加和单据金额不相等");
        } else {
            xxApiDjtsParam.setHjje(mxSumBhsje);
            xxApiDjtsParam.setHjse(mxSumHsje.subtract(mxSumBhsje));
        }

        //差额征税
        if (StringUtils.isNotEmpty(xxApiDjtsParam.getZsfs()) && "2".equals(xxApiDjtsParam.getZsfs())) {
            if (mxlist.size() > 1) {
                throw new JeecgBootException("差额征税明细只能有一条");
            }
            if (StringUtils.isNotEmpty(Convert.toStr(xxApiDjtsParam.getZkje())) || StringUtils.isNotEmpty(Convert.toStr(mxlist.get(0).getZkje()))) {
                throw new JeecgBootException("差额征税不支持折扣");
            }
            if (!"1".equals(xxApiDjtsParam.getHsbz())) {
                throw new JeecgBootException("差额征税请推送含税金额");
            }
            if (StringUtils.isEmpty(Convert.toStr(xxApiDjtsParam.getKce()))) {
                throw new JeecgBootException("差额征税的扣除额不能为空");
            }
        }

    }

    public void fillBasicInfo(XxApiDjtsParam xxApiDjtsParam, CsXxDkdj csXxDkdj) {
        String kpzddm = xxApiDjtsParam.getKpzddm();
        //开票终端
        CsXxKpzd csXxKpzd = iCsXxKpzdService.lambdaQuery().eq(StringUtils.isNotEmpty(kpzddm), CsXxKpzd::getZddm, kpzddm).one();
        //企业信息
        CsPtQyxx csPtQyxx = iCsPtQyxxService.lambdaQuery().eq(CsPtQyxx::getId, csXxKpzd.getCompanyId()).one();
        csXxDkdj.setId(IdWorker.getIdStr());
        csXxDkdj.setCompanyId(csXxKpzd.getCompanyId());
        csXxDkdj.setTenantId(csXxKpzd.getTenantId());
        csXxDkdj.setSjyt(csPtQyxx.getSsyt());//数据业态
        csXxDkdj.setClfs("0");//处理方式 默认0 未处理
        csXxDkdj.setGsdm(csPtQyxx.getNsrdm());
        csXxDkdj.setXfmc(csXxKpzd.getNsrmc());
        csXxDkdj.setXfsh(csXxKpzd.getNsrsbh());
        csXxDkdj.setYhdm("单据推送");
        csXxDkdj.setDjzt("0");//单据状态 默认有效
        csXxDkdj.setKpzt("0");//开票状态 默认未开票
        csXxDkdj.setDjrq(new Date());
        if (StringUtils.isBlank(csXxDkdj.getKpr())) {
            csXxDkdj.setKpr(csXxKpzd.getKpr());
        }
        if (StringUtils.isBlank(csXxDkdj.getFhr())) {
            csXxDkdj.setFhr(csXxKpzd.getFhr());
        }
        if (StringUtils.isBlank(csXxDkdj.getSkr())) {
            csXxDkdj.setSkr(csXxKpzd.getSkr());
        }
    }

    public void filKhInfo(XxApiDjtsParam xxApiDjtsParam, CsXxDkdj csXxDkdj) {
        LambdaQueryWrapper<CsXxCustom> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotEmpty(xxApiDjtsParam.getKhdm()), CsXxCustom::getKhdm, xxApiDjtsParam.getKhdm());
        queryWrapper.eq(StringUtils.isNotEmpty(xxApiDjtsParam.getKhmc()), CsXxCustom::getKhdw, xxApiDjtsParam.getKhmc());
        queryWrapper.eq(StringUtils.isNotEmpty(xxApiDjtsParam.getKhsh()), CsXxCustom::getNsrsbh, xxApiDjtsParam.getKhsh());
        queryWrapper.orderBy(true, false, CsXxCustom::getNsrsbh);
        queryWrapper.orderBy(true, false, CsXxCustom::getKhhzh);
        queryWrapper.orderBy(true, false, CsXxCustom::getLxdz);
        CsXxCustom custom = iCsXxCustomService.getOne(queryWrapper, false);
        if (custom != null) {
            if (StringUtils.isBlank(csXxDkdj.getKhdm())) {
                csXxDkdj.setKhdm(custom.getKhdm());
            }
            if (StringUtils.isBlank(csXxDkdj.getKhsh())) {
                csXxDkdj.setKhsh(custom.getNsrsbh());
            }
            if (StringUtils.isBlank(csXxDkdj.getKhdz())) {
                csXxDkdj.setKhdz(custom.getLxdz());
            }
            if (StringUtils.isBlank(csXxDkdj.getKhyh())) {
                csXxDkdj.setKhyh(custom.getKhhmc());
            }
            if (StringUtils.isBlank(csXxDkdj.getKhzh())) {
                csXxDkdj.setKhzh(custom.getKhhzh());
            }
            if (StringUtils.isBlank(csXxDkdj.getKhdh())) {
                csXxDkdj.setKhdh(custom.getLxdh());
            }
            if (StringUtils.isBlank(csXxDkdj.getKhlxyx())) {
                csXxDkdj.setKhlxyx(custom.getMryx());
            }
            if (StringUtils.isBlank(csXxDkdj.getKhlxfs())) {
                csXxDkdj.setKhlxfs(custom.getLxdh());
            }
        }
    }


}
